<template>
  <div>
     <Header>
      <div slot="mianbaoxie">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>消息页</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </Header>
    <el-table
      :data="tableData"
      style="width: 100%"
      >
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="消息"
        :formatter="formatter">
      </el-table-column>
       <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          :disabled='scope.row.readed'
          :type="scope.row.readed?'info':'primary'"
          @click="handleEdit(scope.$index, scope.row)">点击已读</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { Notification } from 'element-ui'
import Header from '_componet/Header'
export default {
  data() {
    return {
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '吃了吗',
        readed: false
      }, {
        date: '2016-05-04',
        name: '王小',
        address: '上海市在哪',
        readed: true
      }, {
        date: '2016-05-01',
        name: '王虎',
        address: '上号',
        readed: false
      }, {
        date: '2016-05-03',
        name: '张三',
        address: '弄他',
        readed: false
      }]
    }
  },
  methods: {
    handleEdit(index, row) {
      // row.readed=true
      this.tableData[index].readed=true
    },
    handleDelete(index, row) {
      if(row.readed){
        this.tableData.splice(index,1)
      }else{
        Notification.error({
          title: '警告',
          message: '无法删除读消息',
          duration:500
        });
      }
    },
    formatter(row, column) {
      return row.address;
    }
  },
  components: { Header }
}
</script>

<style lang="scss" scoped>

</style>
